<template>
	<view>
		<view class="message-container" v-for="one in list" v-if="list.length > 0">
			<view class="top">
				<view class="title">
					<image src="../../static/message_list/email-icon-1.png" mode="widthFix" v-if="!one.readFlag"></image>
					<image src="../../static/message_list/email-icon-2.png" mode="widthFix" v-if="one.readFlag"></image>
					<text>{{ one.senderName }}</text>
				</view>
				<view class="date">{{ one.sendTime }}</view>
			</view>
			<view class="content">{{ one.msg }}</view>
			<view class="bottom" @tap="toDetail(one)">
				<text>查看详情</text>
				<u-icon name="arrow-right" color="#aaa" size="28"></u-icon>
			</view>
		</view>
		<view class="empty" v-if="list.length == 0"><u-empty text="消息列表为空" mode="list"></u-empty></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			page: 1,
			length: 50,
			list: [],
			isLastPage: false
		};
	},
	methods: {
		toDetail(one){
			uni.navigateTo({
			    url: '../message/message?id='+one.id + '&refId=' + one.refId
			})
		},
		getMessageList() {
			let that = this;
			if(!that.isLastPage) {
				let data = {
					"start": that.page,
					"length": that.length
				}
				this.ajax(this.url.searchMessageByPage, 'POST', data, function(resp){
					let result = resp.data.result;
					if(result.messages.length == 0) {
						that.isLastPage = true;
					}
					for(let i=0;i<result.messages.length;i++) {
						that.list.push(result.messages[i]);
					}
					
				})
			}
		}
	},
	onShow: function() {
		let that = this;
		let data = {
			"start": that.page,
			"length": that.length
		}
		this.ajax(this.url.searchMessageByPage, 'POST', data, function(resp){
			let result = resp.data.result;
			that.list = result.messages;
		})
	},
	onReachBottom: function() {
		this.page++;
		this.getMessageList();
	}
};
</script>

<style lang="less">
@import url('message_list.less');
</style>
